﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Xna.Framework;
using Super_Wall_Breaker.Sources.GameEngine;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Content;

namespace Super_Wall_Breaker.Sources.GameElements.Bricks
{
    public class BasicBrick : Brick
    {

        /// <summary>
        /// Initializes a new instance of the <see cref="BasicBrick"/> class.
        /// </summary>
        public BasicBrick() { }

        /// <summary>
        /// Initializes a new instance of the <see cref="BasicBrick"/> class.
        /// </summary>
        /// <param name="lifeTime">The life time.</param>
        /// <param name="position">The position.</param>
        /// <param name="sourceRectangle">The source rectangle.</param>
        public BasicBrick(int lifeTime, Vector2 position, Rectangle? sourceRectangle)
            : base(lifeTime, position, sourceRectangle)
        {
            if (lifeTime <= GlobalConfiguration.DEFAULT_BRICK_MAX_LIFE)
            {
                this.InitLife = lifeTime;
                this._currentLife = lifeTime;
                this.Break = new Sprite(position, sourceRectangle);
                this.ValueScore = DefaultBrickScrore * this.InitLife;
            }
        }

        /// <summary>
        /// Updates the specified contentManager.
        /// </summary>
        /// <param name="c">The contentManager.</param>
        public override void Update(ContentManager c)
        {
            if (this.CurrentLife == 1)
            {
                this.Break = new Sprite(this.Position, new Rectangle(253, 51, GlobalConfiguration.BRICK_TEXTURE_WIDTH, GlobalConfiguration.BRICK_TEXTURE_HEIGHT));
            }
            else if (this.CurrentLife == 2)
            {
                this.Break = new Sprite(this.Position, new Rectangle(190, 51, GlobalConfiguration.BRICK_TEXTURE_WIDTH, GlobalConfiguration.BRICK_TEXTURE_HEIGHT));
            }
            else if (this.CurrentLife == 3)
            {
                this.Break = new Sprite(this.Position, new Rectangle(127, 51, GlobalConfiguration.BRICK_TEXTURE_WIDTH, GlobalConfiguration.BRICK_TEXTURE_HEIGHT));
            }
            else if (this.CurrentLife == 4)
            {
                this.Break = new Sprite(this.Position, new Rectangle(64, 51, GlobalConfiguration.BRICK_TEXTURE_WIDTH, GlobalConfiguration.BRICK_TEXTURE_HEIGHT));
            }
            this.Break.LoadContent(c, GlobalConfiguration.DEFAULT_SPRITE_SHEET);
            this.Break.LayerDepth = 0.1f;            
        }

        /// <summary>
        /// Draws the specified sprite batch.
        /// </summary>
        /// <param name="spriteBatch">The sprite batch.</param>
        public override void Draw(SpriteBatch spriteBatch)
        {
            if (this.Break != null)
                spriteBatch.Draw(this.Break.Texture, this.Break.Position, this.Break.SourceRectangle, this.Break.Color, this.Break.Rotation, this.Break.Origin, this.Break.Scale, this.Break.Effect, this.Break.LayerDepth);

            base.Draw(spriteBatch);
        }
    }
}
